<script>

	$().ready(function() {
		// validate the comment form when it is submitted
		
		
		// validate signup form on keyup and submit
		$("#setRappresentante").validate({
			rules: {
				datai: {
					required: true,
					date: true
					},
				dataf: {
					required: true,
					date: true
					}
					
			},
			messages: {
				datai: {
					required: "inserisci la data",
					date: "il formato non e' corretto"
				},
				dataf: {
					required: "inserisci la data",
					date: "il formato non e' corretto"
				}
			}
		});
	});	
	$(function()
			{
				$('.date-pick').datePicker({startDate:'01/01/1996'});
			});
</script>

<div id="page">
<div id="content">
<form method="get" id="setRappresentante"
	action="<?php echo BASE_PATH;?>Rappresentante/Update_setRappresentante/?>">
	
<fieldset><legend>Assegna a uno studente il ruolo di rappresentante:</legend>
<ol>
	<li><label for="nome">Corso di laurea :</label>
				
	<select id="corsostudio" name="corsostudio" onchange="getMatricola(this.value);">
   	<option>Seleziona il corso</option>
    <?php foreach ($vars['CorsoStudio'] as $result){
    ?>
    <option id="corsostudio" value="<?php echo $result[IdCorsoStudio] ?>"><?php echo $result[Nome] ?></option>
  	<?php }?>
  	</select>
  
	</li>
	
	<li><label for="nome">Matricola :</label>
		<select id="matricola" name="matricola" onchange="getStudente(this.value);">

		</select>
	</li>
	<li><label for="nome">Nome:</label>
		<input type="text" id="nome" disabled="disabled" />
	</li>
	<li><label for="nome">Cognome:</label>
		<input type="text" id="cognome" disabled="disabled" />
	</li>
	
	</li>
	<li><label for="date1">Data inizio mandato:</label>
		<input type="text" title="date" id="datai" name="datai" size="10" class="date-pick" />
	</li>
	<li><label for="date1">Data fine mandato:</label>
		<input type="text" title="date" id="dataf" name="dataf" size="10" class="date-pick" />
	</li>
	<li><label for="nome">Anno Accademico:</label>
		<select id="annoaccademico" name="annoaccademico">
	<?php foreach ($vars['AnnoAccademico'] as $result){?>
    	<option value="<?php echo $result['IdAnno'] ;?>"><?php echo $result['datainizio'].'/'.$result['datafine'];?></option>
  	<?php }?>
		</select>
	</li>
  </ol>
  <br>
  <br>
		<input type="submit" id="invia" disabled="disabled" value="Invia i dati">

		
</form>

<script type="text/javascript">

function getMatricola(idCorso) {


  $.get("<?php echo BASE_PATH;?>Studente/View_getMatricolaByCorso/", { corsostudio: idCorso, requestItems: 'Matricola'}, 
  function(matricole){

    $("#matricola").html(matricole);
    $("#invia").attr("disabled",false);
    
	});
  
}

function getStudente(studente) {

	  $.get("<?php echo BASE_PATH;?>Studente/View_getNomeCognomeByMatricola/", { matricola: studente, requestItems: 'Nome', requestItems: 'Cognome'}, 
	  function(studente){

			var a=studente.split("/");		
			  
	    $("#nome").attr("value",a[0]);
	    $("#cognome").attr("value",a[1]);

		});
	  
}
</script>
</div>
</div>

	